/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.nii.qlks.GUI.Render;

import java.awt.Color;
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author KUUT
 */
public class TableColor extends JLabel implements TableCellRenderer {

    ImageIcon Icon;
    int a = -1;

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {


        String textValue = String.valueOf(value);

        this.setOpaque(true);
        this.setFont(table.getFont());

        setColor(table, value, isSelected, hasFocus, row, column);

        this.setText(textValue);


        return this;
    }

    public Component setColor(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {

        this.setBackground(row % 2 == 0 ? new Color(255, 255, 134) : Color.WHITE);

        if (isSelected) {
            a = table.getSelectedRow();
        }

//        if(a == row){
//            this.setBackground(Color.GREEN);
//        }

        if (row == table.getSelectedRow()) {
            this.setBackground(Color.cyan);
            this.setForeground(Color.red);
        } else {
            this.setForeground(Color.BLACK);
        }

        return this;

    }
}
